package com.hand.control;


import com.hand.Dao.userDao;
import com.hand.domain.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@RestController
public class FindByName {

    @RequestMapping("/findByName")
    public User findByName() throws IOException {

        InputStream resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        userDao mapper = sqlSession.getMapper(userDao.class);


        //根据name查询
        User user2 = new User();
        user2.setName("z");
        User user = mapper.findByName(user2);
        System.out.println(user);



        sqlSession.commit();
        sqlSession.close();
        return user;
    }


}
